﻿using System;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Noria.Web.MyMSDN.Models;

namespace Noria.Web.Test
{
    [TestClass]
    public class GenerateSeoHtml
    {
        [TestMethod]
        public void GenerateFamily()
        {
            var buffer = new StringBuilder();
            using (var db = new MmContext())
            {
                var cats = db.Categories.Include("Families").ToArray();
                foreach (var category in cats)
                {
                    buffer.AppendFormat("<div data-category='{0}'>", category.Name);
                    foreach (var family in category.Families)
                    {
                        buffer.AppendFormat("<a>{0}</a>", family.Name);
                    }
                    buffer.Append("</div>");
                }
            }
            System.IO.File.WriteAllText("cat.txt", buffer.ToString());
        }
        [TestMethod]
        public void GenerateProduct()
        {
            var buffer = new StringBuilder();
            using (var db = new MmContext())
            {
                var families = db.Families.Include("Files").Where(p => (p.FamilyId == 383/*office 2010*/
                    || p.FamilyId == 475/*office2013*/ || p.FamilyId == 350/*win7*/
                    || p.FamilyId == 481/*win8*/ || p.FamilyId == 140/*xp*/ || p.FamilyId == 479/*vs11*/)
                    ).ToArray();
                foreach (var family in families)
                {
                    buffer.AppendFormat("<div data-family='{0}'>", family.Name);
                    foreach (var file in family.Files.Where(p => p.Locale == "cn" || p.Locale == "en"))
                    {
                        buffer.AppendFormat("<a data-file='{1}' data-sha1='{2}'>{0}</a>", file.Description, file.FileName, file.Sha1);
                    }
                    buffer.Append("</div>");
                }
            }
            System.IO.File.WriteAllText("family.txt", buffer.ToString());
        }
    }
}
